#include "sort.h"
#include "str.h"

void maxHeapify(char** words, int i, int heapSize)
{
	int left = 2*i;
	int right = 2*i+1;

	int largest = 0;

	if (left < heapSize && strcasecmp(words[left], words[i]) > 0)
	{
		largest = left;
	}
	else
	{
		largest = i;
	}

	if (right < heapSize && strcasecmp(words[right], words[largest]) > 0)
	{
		largest = right;
	}

	if (largest != i)
	{
		swap(&words[i], &words[largest]);
		maxHeapify(words, largest, heapSize);
	}
}
